<?php

namespace app\api\model\questions;

use app\api\model\Models;
use think\db\Query;
use app\api\traits\model\questions\Answer as AnswerTraits;

class Answer extends Models
{
    use AnswerTraits;

    /*
     * 定义全局的查询范围
     * @var array
     */
    protected $globalScope = ['noDisplay'];

    /**
     * 设置类型获取器
     * @return string
     */
    protected function getTypeTextAttr( $value, $data )
    {
        $category = config('field.answer.type');
        return $category[$data['type']]??'暂无';
    }

    /**
     * 设置全局不显示字段
     * @param Query $query
     * @return void
     */
    public function scopeNoDisplay( Query $query )
    {
        $query->field('create_at,update_at', true);
    }
}
